#include<bits/stdc++.h>
using namespace std;
#define int long long

int a[10005];

signed main() {
	int n, m;
	cin >> n >> m;
	for (int i = 1; i <= n; i++)
		cin >> a[i];
	do {
		if (!m--)	break;
	} while (next_permutation(a + 1, a + n + 1));
	for (int i = 1; i <= n; i++)
		cout << a[i] << " ";
	return 0;
}
